package com.kaibes.module.file.local.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.kaibes.module.file.local.db.FileInfoService;
import com.kaibes.module.file.local.db.FileMarkService;
import com.kaibes.web.admin.IconBox;
import com.kaibes.web.util.WebUtils;

@Configuration
public class FileLocalBoxInit {

	@Autowired
    private FileInfoService fileInfoService;
	@Autowired
	private FileMarkService fileMarkService;
	
	@Bean
    public IconBox fileInfoBox() {
        IconBox iconBox = new IconBox() {

            @Override
            public void update() {
                setCount(fileInfoService.count());
            }
        };
        iconBox.setSort(21);
        iconBox.setName("文件总数");
        iconBox.setClassAppend("bg-info");
        iconBox.setIcon("ion-clipboard");
        iconBox.setHref("/admin/file/info");
        return iconBox;
    }
	
	@Bean
    public IconBox fileMarkBox() {
        IconBox iconBox = new IconBox() {

            @Override
            public void update() {
                setCount(fileMarkService.count());
            }
        };
        iconBox.setSort(22);
        iconBox.setName("文件标记总数");
        iconBox.setClassAppend("bg-info");
        iconBox.setIcon("ion-clipboard");
        iconBox.setHref("/admin/file/mark");
        return iconBox;
    }
	
	@Bean
    public IconBox userFileMarkBox() {
        IconBox iconBox = new IconBox() {

            @Override
            public void update() {
            	Integer userId = WebUtils.getAttribute("userId");
            	if (userId != null) {
            		setCount(fileMarkService.countByUserId(userId));
            	}
            }
        };
        iconBox.setSort(23);
        iconBox.setName("用户文件总数");
        iconBox.setClassAppend("bg-info");
        iconBox.setIcon("ion-clipboard");
        iconBox.setHref("/admin/file/mark/self");
        return iconBox;
    }
	
}
